<?php

namespace frontend\controllers;

use yii\web\Controller;
use yii\web\Response;
use yii2mod\query\ArrayQuery;

class PublicController extends Controller
{
    public function actionAjaxGetFztBanks($q = null, $json_data= null)
    {
        \Yii::$app->response->format = Response::FORMAT_JSON;
        $banks = \Yii::$app->fenZhangTong->getBanks();
        $query = (new ArrayQuery())->from($banks);
        $out = ['results' => [['id' => '', 'text' => '']]];
        if ($q) {
            $query->andFilterWhere(['like', 'name', $q]);
        }
        $data = $query->limit(10)->all();
        $results = [];
        foreach ($data as $k => $v) {
            $results[] = ['id' => $v['code'], 'text' => $v['name']];
        }
        $out['results'] = $results;
        return $out;
    }
}